package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.IOException;
import java.time.Duration;

public class TemplatePage extends Utils {
    public static String url="http://8.155.1.153:8081/template";
    public TemplatePage() {
        super(url);
    }

    public void checkPageRight() throws IOException {
        //查看页面关键元素
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[1]/div[1]/div/span"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/span/span/input"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/span/span/span/button"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button"));
        driver.findElements(By.xpath("//*[@id=\"rc-tabs-0-tab-public\"]"));
        driver.findElement(By.xpath("//*[@id=\"rc-tabs-0-tab-private\"]"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[1]/div[1]/span"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[2]/div[1]/span"));
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }

    //新增模版
    public void NewTem() throws InterruptedException, IOException {
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button")).click();

        // 定位抽屉主体
        WebElement drawerBody = driver.findElement(By.className("ant-drawer-body"));
        //点击单选题
        /*drawerBody.findElement(By.cssSelector("div.menu-group-item")).click();*/
        WebElement singleChoiceItem = driver.findElement(By.cssSelector("div.menu-group-item"));
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("arguments[0].click();", singleChoiceItem);

        //点击保存
        drawerBody.findElement(By.cssSelector("div.ant-btn-group.ant-btn-group-sm > button.ant-btn.ant-btn-primary.ant-btn-sm:last-child")).click();

        /*//弹窗新建模版
        WebElement modal = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("//*[@id=\"rc_unique_0\"]")));*/
        //名称  分类
        driver.findElement(By.xpath("//*[@id=\"name\"]")).sendKeys("ceshi001");
        driver.findElement(By.xpath("//*[@id=\"category\"]")).sendKeys("ceshi001");

        driver.findElement(By.xpath("//*[@id=\"survey-modal-container\"]/div/div/div[2]/div/div[2]/div[3]/button[2]")).click();

        driver.navigate().back();
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/aside/div/div[1]/ul/li[5]/span/a")).click();
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());


    }
}

